// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1

Item {
    id: root
    height: rect.height

    signal clique(int idBotao)

    property string texto : ""
    property color corFundo: "red"
    property color corFundoClicado: "blue"
    property color corTexto : "white"
    property int idBotao: -1

    Rectangle {
        id: rect
        anchors { left: parent.left; top: parent.top; right: parent.right; margins: 2 }
        height: txtObj.height + 20
        color: root.corFundo
        radius: 5
        clip: true
        state: "NAOCLICADO"

        Text {
            id: txtObj
            anchors.centerIn: parent
            font { pixelSize: 20; bold: true; }
            color: root.corTexto
            text: root.texto
        }

        MouseArea {
            anchors.fill: parent
            onClicked: {
                rect.state = "CLICADO";
            }
        }

        states: [
            State {
                name: "NAOCLICADO"
                PropertyChanges {
                    target: rect
                    color: root.corFundo
                }
            },
            State {
                name: "CLICADO"
                PropertyChanges {
                    target: rect
                    color: root.corFundoClicado
                }
            }
        ]

        transitions: [
            Transition {
                from: "NAOCLICADO"
                to: "CLICADO"
                reversible: true
                SequentialAnimation {
                    ColorAnimation { target: rect; duration: 200 }
                    PauseAnimation { duration: 50 }
                    ScriptAction {
                        script: {
                            if (rect.state == "CLICADO")
                                root.clique(root.idBotao);
                            rect.state = "NAOCLICADO";
                        }
                    }
                }
            }
        ]
    }

}
